//载入那些函数库
let includes = ([
    "include/common.js",
]);

//继承哪些JS 在所有代码之前要完成继承
let inherits = ([
    "inherit/data.js",
    "inherit/room.js"
]);


//被创建的时候触发
function create() {

    let ob = thisObject();

    ob.set("id", "roundBattle");
    ob.set("name", "回合战斗房间");
    //是否是玩家
    ob.set("obType", "isRoom");
    ob.set("heartbeat", 1);
    //战斗中的阵营
    ob.set("kill1", []);
    ob.set("kill2", []);
    return ob;

}


function getKiller(killer) {
    let me = thisObject();
    //取出杀手..
    let kills = me.get(killer);
    for (let k in kills) {
        //选择可战斗的
        if ( !kills[k].get("hasFight") && !kills[k].getTemp("rdDead") ) {
            return kills[k];
        }
    }
    return false;
}


function addKills(tag, ary) {

    let me = thisObject();
    if (tag != "kill1" && tag != "kill2") {
        os.debug("战斗阵营的标识只能是kill1或者kill2");
        return false;
    }

    me.set(tag, ary);
}



function testMe() {
    me = thisObject();
    os.debug("我是战场子类");
}

let kstr = "kill1", vstr = "kill2";


function heartbeat() {

    let me = thisObject();
    // os.debug(me.parentHp, "最大血量");
    //交替战斗
    let killer, victim;
    if (!(killer = me.getKiller(kstr))) {
        os.debug("没有杀手");
        return;
    }

    if (!(victim = me.getKiller(vstr))) {
        os.debug("没有被杀者");
        return;
    }

    // me.testMe();
    // me.parent("inherit/room.js").testMe();

    // os.D("daemons/fixRoundPlayd.js").combat(1,1);

    //os.debug( D("daemons/fixRoundPlayd.js"),"对象到底傻眼" )

    D("daemons/fixRoundPlayd.js").combat(killer, victim);

    if( victim.get("hp") <=0){
        //标记战斗结束
        victim.setTemp("rdDead",true);

    }



    //os.debug(me.parent("inherit/room.js"), "父类是什么？");
    // me.parent("inherit/room.js").addKills("","");
    //
    // let killerHp = killer.get("hp");
    // let victimHp = victim.get("hp");
    //
    // os.debug("杀手的血量" + killerHp + "被杀者的血量" + victimHp);


    if (kstr == "kill1") {
        kstr = "kill2";
        vstr = "kill1"
    } else {
        kstr = "kill1";
        vstr = "kill2"
    }


    return {};
}

